<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>表单输入绑定</title>
</head>
<body>
  <div id="app">
    <input type="text" placeholder="用户名" v-model.lazy.trim.number="username" /> {{ username }} </br>
    <input type="password" placeholder="密码" v-model="password" /> </br>
    <input type="radio" v-model="sex" value="1">男 
    <input type="radio" v-model="sex" value="0">女</br>

    <input type="checkbox" v-model="hobby" value="1">吃饭
    <input type="checkbox" v-model="hobby" value="2">睡觉
    <input type="checkbox" v-model="hobby" value="3">打豆豆</br>

    <select v-model="city">
      <!-- 第一个是为了兼容性 --- 苹果的safari浏览器默认选不中第一个 -->
      <option disabled>请选择</option>
      <option value="1">太原</option>
      <option value="2">上海</option>
      <option value="3">北京</option>
    </select></br>
    <textarea v-model="note"></textarea></br>
    <input type="checkbox" v-model="flag">同意此协议</br>
    <input type="button" value="提交" @click="getInfo">
  </div>
</body>
<script src="vue.js"></script>
<script>
  // checkbox   select
new Vue({
  el: '#app',
  data: {
    username: '吴大勋',
    password: '123456',
    sex: '1',
    hobby: ['1', '3'],
    city: '2',
    note: '',
    flag: true
  },
  methods: {
    getInfo () {
      // const obj = {
      //   username: this.username,
      //   password: this.password,
      //   sex: this.sex === '1' ? '男' : '女',
      //   hobby: this.hobby,
      //   city: this.city,
      //   note: this.note,
      //   flag: this.flag
      // }
      // if (!this.flag) {
      //   alert('请先勾选协议')
      //   return
      // }
      console.log(this.username)
    }
  }
})
</script>
</html>